/**
 *	Monopolymorphism - A Java-based monopoly!
 *
 *	The final project of 
 *	Object-Oriented Programming Design of NTUCSIE
 *
 *	Authors:
 *		ChungKingSing.
 *		Qing-Cheng Li.
 */
package monopolymorphism;

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public abstract class Land{
	protected int id;
	protected char type;
	public abstract void action(Player x);
}

class NormalLand extends Land{
	private Property property;
	public NormalLand(int _id,Property _property){
		id = _id;
		property = _property;
		type = 'N';
	}
	public void action(Player x){
		System.out.println("NormalLand"+id);
		System.out.println(property.type);
		System.out.println(property.name);
	
		if(property.owner!=null){
			if(x!=property.owner){
				this.payRent(x);
			}
		}else{
			System.out.println("Do you want to buy this land?(1)yes(2)no");
			Scanner jin = new Scanner(System.in);
			switch(jin.nextInt()){
				case 1:
					x.buy(property);
					break;
				case 2:
					break;
				default:
					break;
			}
		}
	}
	private void payRent(Player x){
		System.out.println("Pay "+property.rent()+" to "+property.owner.getName());
		if(!x.bankruptcy(property.rent()))
			x.pay(property.rent(),property.owner);
		else{
			x.pay(x.getMoney(),property.owner);
			x.isBankruptcy = true;//bankruptcy!
		}
	}
	
}

class MoneyLand extends Land{
	private int bouns;
	public MoneyLand(int _id,int _bouns){
		id = _id;
		bouns = _bouns;
		type = 'M';
	}
	public void action(Player x){
		System.out.println("MoneyLand"+id);
		if(bouns>=0)
			x.addMoney(bouns);
		else
			if(!x.bankruptcy((-1*bouns)))
				x.addMoney(bouns);	//money-
			else
				x.isBankruptcy = true;	//bankruptcy!
	} 
}

class SpecialLand extends Land{
	public SpecialLand(int _id){
		id = _id;
		type = 'S';
	}
	public void action(Player x){
		System.out.println("SpecialLand"+id);
		if(x.location==30){
			System.out.println("In Jail 3 Day!");
			x.location = 10;
			x.inJail = true;
			x.inJailDay = 3;
		}
		
		if(x.location==0||x.location==20){
			System.out.println("Get 1000");
			x.addMoney(1000);
		}
	
	}
}

class CardLand extends Land{
	private Card card;
	public CardLand(int _id,Card _card){
		id = _id;
		card = _card;
		type = 'C';
	}
	public void action(Player x){
		System.out.println("CardLand"+id);
		/*
		if(card.type=='C'){
		}else{
		}
		*/
		card.action(card.getCard(),x);
		
	}
}

